﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class InterfaceHpSystemUI
{

    private ActiveObject player;
    private GameObject hpPoint;


    public void setTarget(ActiveObject player)
    {
        this.player = player;
    }


    public void onFixedProc(SystemUIEventScript UIParent)
    {
        refreshHPUI(UIParent);
    }


    public void refreshHPUI(SystemUIEventScript UIParent)
    {

        if (player && Com.checkObjectTime(UIParent, "GLOBAL_HP_PRECENT_COUNT", 0.1f))
        {

            if (hpPoint != null)
            {

                float rate = player.getHp() / player.getHpMax();
                Vector2 theScale = hpPoint.transform.localScale;
                theScale.x = rate;
                hpPoint.transform.localScale = theScale;
            }
            else
            {
                hpPoint = Com.getCompoment(UIParent.gameObject, "UI", "HpSystem", "point");
            }
        }
        
        
    }

}
